package com.example.demo.easyexcel.db.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import com.example.demo.easyexcel.dao.CityExcelSelectedImpl;
import com.example.demo.easyexcel.util.SelectUtil.ExcelSelected;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;

/**
 * @author zjq
 * @version 创建时间：2021-12-17 15:24:52
 */
@Data
@ContentRowHeight(10) // 设置 Cell 高度 为10
@HeadRowHeight(20) // 设置表头 高度 为 20
@ColumnWidth(15) // 列宽25
@ApiModel(value = "用户表")
@Entity
@Table(name = "base_user")
public class BaseUser {

    @ExcelIgnore // 这个字段不会生成
    @Column(name = "id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    // 头背景设置成红色 IndexedColors.RED.getIndex()
    @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10)
    @ExcelProperty(index = 0, value = "用户姓名") // excel标题
    @ApiModelProperty(value = "用户姓名")
    @Column(name = "name")
    private String name;

    // 静态下拉框
    @ExcelSelected(source = {"男", "女"})
    @ExcelProperty(index = 1, value = "性别")
    @ApiModelProperty(value = "性别")
    @Column(name = "sex")
    private String sex;

    @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10)
    @ColumnWidth(30) // 宽度50
    @ExcelProperty(index = 2, value = "身份证")
    @ApiModelProperty(value = "身份证")
    @Column(name = "idcard")
    private String idcard;

    // 动态下拉框-去数据库中查询所有城市供其选择---可能会出现问题，建议用公司的
    @ExcelSelected(sourceClass = CityExcelSelectedImpl.class)
    @ExcelProperty(index = 3, value = "城市")
    @Column(name = "city")
    @ApiModelProperty(value = "城市")
    private String city;

}
